//
//  LzwLandingViewController.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/6.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwLandingViewController.h"
#import "LzwLandingView.h"
#import "LzwBaseImageView.h"
#import "LzwLoginViewController.h"
@interface LzwLandingViewController ()<LzwLandViewDelegata>

@property (nonatomic, retain) LzwBaseImageView *landImage;
@property (nonatomic, retain) LzwLandingView *landView;

@end

@implementation LzwLandingViewController

-(void)dealloc{
    [_landImage release];
    [_landView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"用户登陆";
    
    //设置导航栏字体颜色和大小
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:20 * WIDTH],
       
       
       NSForegroundColorAttributeName:[UIColor blackColor]}];
    
    
    UIImage * LandRightBar = [UIImage imageNamed:@"return.png"];
    LandRightBar = [LandRightBar imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:LandRightBar style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction:)];
    

    
    self.landView = [[LzwLandingView alloc]initWithFrame:self.view.bounds];
    self.landView.backgroundColor = [UIColor whiteColor];
    self.landView.myLandDelegata = self;
    [self.view addSubview:self.landView];
    
    

    
}

//签订协议push到注册页面
- (void)pushZhucePage{
    LzwLoginViewController *longinVC = [[LzwLoginViewController alloc]init];
    
    [self.navigationController pushViewController:longinVC animated:YES];
    
}
//签订协议登陆按钮
- (void)LandingButtonAction{
    
    if (self.landView.landingText1.text.length <= 0 || self.landView.landingText2.text.length <= 0) {
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆账号或密码不能为空" preferredStyle:UIAlertControllerStyleAlert];
        [self presentViewController:alert animated:YES completion:^{
            
            
        }];
        
        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alert addAction:alertA];
        return;
    }
    
    NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"name"];
    
    NSString *pass = [[NSUserDefaults standardUserDefaults]objectForKey:@"pass"];
    
    if ([self.landView.landingText1.text isEqualToString:name] && [self.landView.landingText2.text isEqualToString:pass]) {
        
        UIAlertController *alertY = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆成功" preferredStyle:UIAlertControllerStyleAlert];
        
           [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"states"];
        
        [self presentViewController:alertY animated:YES completion:^{
            
           [self dismissViewControllerAnimated:YES completion:^{
               
               [self dismissViewControllerAnimated:YES completion:^{
                   
                   
               }];
               
           }];
        }];
        
     
        
        return;
    }else{
        
        UIAlertController *alertN = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码错误" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alertN animated:YES completion:^{
            
            
        }];
        
        UIAlertAction *acN = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alertN addAction:acN];
        
        
        
    }
    
    
    
}


//返回按钮触发事件
- (void)leftButtonAction:(UIBarButtonItem *)bu{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
